﻿<?php
require('configs/include.php');

class c_editar_programa extends super_controller {
    
    
    public function editar(){
            $programa = new programa($this->post);
             if (is_empty($programa->get('nombre'))) {
            throw_exception("Debe ingresar el nombre del programa antes de continuar");
            }if (is_empty($programa->get('funcionalidad'))) {

            throw_exception("Debe ingresar la funcionalidad del programa  antes de continuar");
            }
            if (is_empty($programa->get('codigo_fuente'))) {

            throw_exception("Debe ingresar el codigo de fuente del programa  antes de continuar");
        }
            if(is_empty($programa->get('fecha_envio'))){
        
            $this->orm->connect();
            $this->orm->update_data("by_editar", $programa);
            $this->orm->close();  
            }
            else{
               
                $programa->set('programador', $_SESSION['usuario']['cedula']);
                $this->orm->connect();
                $this->orm->insert_data("normal", $programa);
                $this->orm->close();  
            }
           
           
            $this->type_warning = "success";
            $this->msg_warning = "Se editó correctamente el programa";
            $this->img_warning = "correct.png";
           
            $this->engine->assign('type_warning', $this->type_warning);
            $this->engine->assign('msg_warning', $this->msg_warning);
             $this->engine->assign('img_warning', $this->img_warning);
            $this->temp_aux = 'message.tpl';
            
            
    }

    public function display() {
            $cod['programa']['id_programador'] = $_SESSION['usuario']['cedula'];
            $options['programa']['lvl2'] = "by_programador1";
            $this->orm->connect();
            $this->orm->read_data(array("programa"), $options, $cod);
            $programas = $this->orm->get_objects("programa");
            //print_r2($programas);
            $this->engine->assign('programas', $programas);
            $this->orm->close();
        
        

        $varAux = $this->gvar['n_index'] . " -> " . $this->gvar['n_program'];
        $this->engine->assign('ubicationPath', $varAux);
        $this->engine->display('header.tpl');
        $this->engine->display($this->temp_aux); 
        $this->engine->display('editar_programa.tpl');
        $this->engine->display('footer.tpl');
    }

    public function run() {
        $typeSession = $_SESSION['usuario']['tipo'];
        if ($typeSession == "lider" || $typeSession == "programador" || $typeSession == "intermediario") {
        
             try {
                if (isset($this->get->option)) {
                    $this->{$this->get->option}();
                }
            } catch (Exception $e) {
                $this->error = 1;
                $this->msg_warning = $e->getMessage();
                $this->img_warning = "incorrect.png";
                $this->engine->assign('type_warning', $this->type_warning);
                $this->engine->assign('msg_warning', $this->msg_warning);
                $this->engine->assign('img_warning', $this->img_warning);
                $this->temp_aux = 'message.tpl';
            }
            
            $this->display();
        } else {
            $this->engine->display('header.tpl');
            $this->engine->display('sinPermisos.tpl');
            $this->engine->display('footer.tpl');
        }
    }

}

$call = new c_editar_programa();
$call->run();
?>